package com.erp.controller.user;

import com.erp.service.UserService;
import com.erp.utils.ExceptionUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeleteUserServlet extends HttpServlet {
    UserService userService = new UserService();
    ExceptionUtil exceptionUtil = new ExceptionUtil();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException{
        //实现，调用userService中的delete方法
        String id = req.getParameter("id");
        try {
            userService.deleteById(Integer.parseInt(id));
            resp.sendRedirect(req.getContextPath()+"/doUserList");
        }catch (Exception e){
            exceptionUtil.error(e.getMessage(),"doUserList",this.getServletContext(),
                    req,resp);
        }
    }
}
